Steve adds line styling to TPO3 reader.
authorrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 5 Apr 2012 17:02:23 +0000 (17:02 +0000)
committerrobertlipe@gmail.com <robertlipe@gmail.com@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 5 Apr 2012 17:02:23 +0000 (17:02 +0000)
Hacked KML writer to discard control characters in a description.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4170 f51c46e8-681c-474f-0cfe-069cfd0219fb

gpsbabel/kml.c
gpsbabel/reference/LineStyles.kml
gpsbabel/tpo.c

index ccd023c0953120f4185b757959d464f9f3e4163b..4d9ee0dbbcbc34ff3bec86d916acb59685a1ffff 100644 (file)
@@ -1473,7 +1473,18 @@ static void kml_waypt_pr(const waypoint* waypointp)
     xfree(odesc);
   } else {
     if (strcmp(waypointp->shortname, waypointp->description)) {
-      kml_write_xmle("description", waypointp->description);
+      // This is a hack.  The entitizer code really should catch this,
+      // but this is the low risk fix for now - just toss bad chars.
+      int j;
+      char* t = xstrdup(waypointp->description);
+      for (j = 0; t[j] != 0; j++) {
+        if (t[j] < ' ') {
+          t[j] = ' ';
+        }
+      }
+
+      kml_write_xmle("description", t);
+      xfree(t);
     }
   }
 
index 6753a4c082bb97b0e35f4052d87dbff92c647376..86137c815c80ec3f24243a0d94a8a37201e3859a 100644 (file)
       </Placemark>
       <Placemark>
         <name>NOTE 1</name>
-        <description>12 test lines - see notes with GPX sample!!\rfour line widths for solid red\rtwo line widths for dashed red\rseven colors for medium width\rNote that line names have nothing at all to do with line style attributes!\vThese are named for convenient cross-reference,\r   but keep in mind that &quot;red med&quot; is a line label and &quot;Red Medium&quot; is a style label.\rWaypoints are generated by Topo to exactly match the first track point.\rApparently only GPX and KML output from GPSBabel retain track descriptions??</description>
+        <description>12 test lines - see notes with GPX sample!! four line widths for solid red two line widths for dashed red seven colors for medium width Note that line names have nothing at all to do with line style attributes! These are named for convenient cross-reference,    but keep in mind that &quot;red med&quot; is a line label and &quot;Red Medium&quot; is a style label. Waypoints are generated by Topo to exactly match the first track point. Apparently only GPX and KML output from GPSBabel retain track descriptions??</description>
         <styleUrl>#waypoint</styleUrl>
         <Point>
           <coordinates>-122.277670,37.522060</coordinates>
       </Placemark>
       <Placemark>
         <name>NOTE 2</name>
-        <description>how GPX from GPSBabel shows Topo track desc as of 2012:\r(line name and line style are NOT related to actual color or width)\r\r&lt;trk&gt;\r  &lt;name&gt;red line&lt;/name&gt;\r  &lt;desc&gt;Style=red med, Width=3, Dashed=0, Color=#ff0000&lt;/desc&gt;\r&lt;number&gt;1&lt;/number&gt;\r&lt;trkseg&gt;\r...\r(Topo menu colors are stored in the file as web-style hex RGB)\r  Red=#ff0000, Yellow=#ffff00, Green=#008000, Blue=#000080,\r  Purple=#800080, Black=#000000, White=#ffffff\r(Topo solid  line widths: Hairline=1, Thin=2, Medium=3, Thick=4)\r(Topo dashed line widths: Hairline=1, Thin=2)\rSRE&apos;s tpo.c mod stuffs Style/Width/Dashed/Color fields into &quot;desc&quot; field\r  under the assumption that something will post-process GPX or KML output\r  and move information from desc to private extensions\r(solid  lines have &quot;Dashed=0&quot;, can have width of 1=hairline to 4=thick)\r(dashed lines have &quot;Dashed=1&quot;, can only have width of 1=hairline or 2=thin)\r</description>
+        <description>how GPX from GPSBabel shows Topo track desc as of 2012: (line name and line style are NOT related to actual color or width)  &lt;trk&gt;   &lt;name&gt;red line&lt;/name&gt;   &lt;desc&gt;Style=red med, Width=3, Dashed=0, Color=#ff0000&lt;/desc&gt; &lt;number&gt;1&lt;/number&gt; &lt;trkseg&gt; ... (Topo menu colors are stored in the file as web-style hex RGB)   Red=#ff0000, Yellow=#ffff00, Green=#008000, Blue=#000080,   Purple=#800080, Black=#000000, White=#ffffff (Topo solid  line widths: Hairline=1, Thin=2, Medium=3, Thick=4) (Topo dashed line widths: Hairline=1, Thin=2) SRE&apos;s tpo.c mod stuffs Style/Width/Dashed/Color fields into &quot;desc&quot; field   under the assumption that something will post-process GPX or KML output   and move information from desc to private extensions (solid  lines have &quot;Dashed=0&quot;, can have width of 1=hairline to 4=thick) (dashed lines have &quot;Dashed=1&quot;, can only have width of 1=hairline or 2=thin) </description>
         <styleUrl>#waypoint</styleUrl>
         <Point>
           <coordinates>-122.284910,37.522349</coordinates>
       </Placemark>
       <Placemark>
         <name>NOTE 3</name>
-        <description>how KML from GPSBabel shows Topo track desc as of 2012:\r(see important notes with GPX sample, all of them apply here!)\r(note that GPSBabel forces all track styles to be the same - why?)\r\r    &lt;Folder&gt;\r      &lt;name&gt;Tracks&lt;/name&gt;\r      &lt;Folder&gt;\r        &lt;name&gt;red line&lt;/name&gt;\r        &lt;snippet/&gt;\r        &lt;description&gt;\r&lt;![CDATA[&lt;table&gt;\r            &lt;tr&gt;&lt;td&gt;&lt;b&gt;Description&lt;/b&gt; Style=Red Medium, Width=3, Dashed=0, Color=#ff0000 &lt;/td&gt;&lt;/tr&gt;\r            &lt;tr&gt;&lt;td&gt;&lt;b&gt;Distance&lt;/b&gt; 1.3 mi &lt;/td&gt;&lt;/tr&gt;\r          &lt;/table&gt;]]&gt;\r        &lt;/description&gt;\r        &lt;Folder&gt;\r          &lt;name&gt;Points&lt;/name&gt;\r          &lt;Placemark&gt;\r            &lt;name&gt;red line-0&lt;/name&gt;\r...</description>
+        <description>how KML from GPSBabel shows Topo track desc as of 2012: (see important notes with GPX sample, all of them apply here!) (note that GPSBabel forces all track styles to be the same - why?)      &lt;Folder&gt;       &lt;name&gt;Tracks&lt;/name&gt;       &lt;Folder&gt;         &lt;name&gt;red line&lt;/name&gt;         &lt;snippet/&gt;         &lt;description&gt; &lt;![CDATA[&lt;table&gt;             &lt;tr&gt;&lt;td&gt;&lt;b&gt;Description&lt;/b&gt; Style=Red Medium, Width=3, Dashed=0, Color=#ff0000 &lt;/td&gt;&lt;/tr&gt;             &lt;tr&gt;&lt;td&gt;&lt;b&gt;Distance&lt;/b&gt; 1.3 mi &lt;/td&gt;&lt;/tr&gt;           &lt;/table&gt;]]&gt;         &lt;/description&gt;         &lt;Folder&gt;           &lt;name&gt;Points&lt;/name&gt;           &lt;Placemark&gt;             &lt;name&gt;red line-0&lt;/name&gt; ...</description>
         <styleUrl>#waypoint</styleUrl>
         <Point>
           <coordinates>-122.288962,37.522691</coordinates>
       </Placemark>
       <Placemark>
         <name>NOTE 4</name>
-        <description>how MapSource 6.16.3 adds color to a track as of 2012:\r(color choices are Dark Gray, Red, Green, Yellow, Blue, Magenta, Cyan, White, Transparent)\r(should be easy to turn desc tag into their extension, but better to directly write track styles)\r\r  &lt;trk&gt;\r    &lt;name&gt;Hwy 50 from Placerville&lt;/name&gt;\r    &lt;extensions&gt;\r      &lt;gpxx:TrackExtension xmlns:gpxx=&quot;http://www.garmin.com/xmlschemas/GpxExtensions/v3&quot;&gt;\r        &lt;gpxx:DisplayColor&gt;Red&lt;/gpxx:DisplayColor&gt;\r      &lt;/gpxx:TrackExtension&gt;\r    &lt;/extensions&gt;\r    &lt;trkseg&gt;\r...\r</description>
+        <description>how MapSource 6.16.3 adds color to a track as of 2012: (color choices are Dark Gray, Red, Green, Yellow, Blue, Magenta, Cyan, White, Transparent) (should be easy to turn desc tag into their extension, but better to directly write track styles)    &lt;trk&gt;     &lt;name&gt;Hwy 50 from Placerville&lt;/name&gt;     &lt;extensions&gt;       &lt;gpxx:TrackExtension xmlns:gpxx=&quot;http://www.garmin.com/xmlschemas/GpxExtensions/v3&quot;&gt;         &lt;gpxx:DisplayColor&gt;Red&lt;/gpxx:DisplayColor&gt;       &lt;/gpxx:TrackExtension&gt;     &lt;/extensions&gt;     &lt;trkseg&gt; ... </description>
         <styleUrl>#waypoint</styleUrl>
         <Point>
           <coordinates>-122.272938,37.522105</coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff0000ff</color>
+              <width>4</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff00ffff</color>
+              <width>3</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff800000</color>
+              <width>3</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff000000</color>
+              <width>3</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff0000ff</color>
+              <width>3</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff0000ff</color>
+              <width>2</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff0000ff</color>
+              <width>1</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>500000ff</color>
+              <width>2</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>500000ff</color>
+              <width>1</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff008000</color>
+              <width>3</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ff800080</color>
+              <width>3</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
         <Placemark>
           <name>Path</name>
           <styleUrl>#lineStyle</styleUrl>
+          <Style>
+            <LineStyle>
+              <color>ffffffff</color>
+              <width>3</width>
+            </LineStyle>
+          </Style>
           <LineString>
             <tessellate>1</tessellate>
             <coordinates>
index 6d0b74687af7b7de5cba8554f55d33f3798c56cf..251fbbfecf87414de601dd6a0cdd110467f0c26e 100644 (file)
@@ -534,6 +534,7 @@ void tpo_process_tracks(void)
 {
   unsigned int track_count, track_style_count;
   unsigned int xx,ii,tmp;
+#define TRACKNAMELENGTH 256
 
   int DEBUG=0;
 
@@ -551,11 +552,10 @@ void tpo_process_tracks(void)
   if (DEBUG) {
     printf("Unpacking %d track styles...\n",track_style_count);
   }
-  char style_name[track_style_count][256]; // some huge value
-  char style_color[track_style_count][7];  // web color is 6 chars
+  char style_name[track_style_count][TRACKNAMELENGTH]; // some huge value
+  int style_color[track_style_count][3];  // keep R/G/B values separate because line_color needs BGR
   int style_wide[track_style_count],style_dash[track_style_count];
   for (ii = 0; ii < track_style_count; ii++) {
-    style_color[ii][0] = '\0';
 
     // clumsy way to skip two undefined bytes
     for (xx = 0; xx < 2; xx++) {
@@ -564,20 +564,24 @@ void tpo_process_tracks(void)
     }
 
     // next three bytes are RGB color, fourth is unknown
+    // Topo and web uses rrggbb, also need line_color.bbggrr for KML
     for (xx = 0; xx < 3; xx++) {
-      tmp = (unsigned char) gbfgetc(tpo_file_in);
-      sprintf(style_color[ii], "%s%02x",style_color[ii],tmp);
+      style_color[ii][xx] = (int) gbfgetc(tpo_file_in);
+      if((style_color[ii][xx] < 0) || (style_color[ii][xx] >255)) {
+        style_color[ii][xx] = 0; // assign black if out of range 0x00 to 0xff
+        // used to store strings: sprintf(style_color[ii], "%s%02x",style_color[ii],tmp);
+      }
     }
 
     tmp = (unsigned char) gbfgetc(tpo_file_in);
-    // printf("Skipping unknown byte 0x%x after color=%s\n",tmp,style_color);
+    // printf("Skipping unknown byte 0x%x after color\n",tmp);
 
     // byte for name length, then name
     tmp = (unsigned char) gbfgetc(tpo_file_in);
     // wrong byte order?? tmp = tpo_read_int(); // 16 bit value
     // printf("Track %d has %d-byte (0x%x) name\n",ii,tmp,tmp);
-    if (tmp >= 256) {
-      printf("ERROR! Found track style over 128 chars, skipping tracks\n");
+    if (tmp >= TRACKNAMELENGTH) {
+      printf("ERROR! Found track style over TRACKNAMELENGTH chars, skipping all tracks!\n");
       return;
     }
     if (tmp) {
@@ -607,7 +611,7 @@ void tpo_process_tracks(void)
     }
 
     if (DEBUG) {
-      printf("Track style %d: color=#%s, width=%d, dashed=%d, name=%s\n",ii,style_color[ii],style_wide[ii],style_dash[ii],style_name[ii]);
+      printf("Track style %d: color=#%02x%02x%02x, width=%d, dashed=%d, name=%s\n",ii,style_color[ii][0],style_color[ii][1],style_color[ii][2],style_wide[ii],style_dash[ii],style_name[ii]);
     }
   }
 
@@ -649,7 +653,8 @@ void tpo_process_tracks(void)
     int lon = 0;
     unsigned int jj;
     route_head* track_temp;
-
+    char rgb[7],bgr[7];
+    int bbggrr = 0;
 
     // Allocate the track struct
     track_temp = route_head_alloc();
@@ -662,7 +667,7 @@ void tpo_process_tracks(void)
     track_style = tpo_read_int(); // index into freehand route styles defined in this .tpo file
     track_style -= 1;  // STARTS AT 1, whereas style arrays start at 0
 
-    // Can be 8/16/32-bit value
+    // Can be 8/16/32-bit value - never used?
     track_length = tpo_read_int();
 
 //UNKNOWN DATA LENGTH
@@ -677,13 +682,30 @@ void tpo_process_tracks(void)
       xasprintf(&track_name, "TRK %d", ii+1);
     }
     track_temp->rte_name = track_name;
+
+    // RGB line_color expressed for html=rrggbb and kml=bbggrr - not assigned before 2012
+    sprintf(rgb,"%02x%02x%02x",style_color[track_style][0],style_color[track_style][1],style_color[track_style][2]);
+    sprintf(bgr,"%02x%02x%02x",style_color[track_style][2],style_color[track_style][1],style_color[track_style][0]);
+    sscanf(bgr,"%06x",&bbggrr); // hex string to integer - probably not the best way to do style_color to bbggrr
+    track_temp->line_color.bbggrr = bbggrr;
+
+    // track texture (dashed=1, solid=0) mapped into opacity - not assigned before 2012
+    track_temp->line_color.opacity = 0xff;   // 255
+    if(style_dash[track_style]) {
+      track_temp->line_color.opacity = 0x50;
+    }
+
+    // track width, from 1=hairline to 4=thick in Topo - not assigned before 2012
+    //  (what are correct values for KML or other outputs??)
+    track_temp->line_width = style_wide[track_style];
+
     if (DEBUG) printf("Track Name: %s, ?Type?: %d, Style Name: %s, Width: %d, Dashed: %d, Color: #%s\n",
-                        track_name, line_type, style_name[track_style], style_wide[track_style], style_dash[track_style], style_color[track_style]);
+                        track_name, line_type, style_name[track_style], style_wide[track_style], style_dash[track_style],rgb);
 
     // Track description
     // track_temp->rte_desc = NULL; // pre-2012 default, next line from SRE saves track style as track description
     xasprintf(&track_temp->rte_desc, "Style=%s, Width=%d, Dashed=%d, Color=#%s",
-            style_name[track_style], style_wide[track_style], style_dash[track_style], style_color[track_style]);
+            style_name[track_style], style_wide[track_style], style_dash[track_style], rgb);
 
     // Route number
     track_temp->rte_num = ii+1;